/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.apilist.validate;


import io.swagger.v3.oas.annotations.media.Schema;
import yhao.infra.common.model.Pagination;

import jakarta.validation.constraints.Min;

/**
 * 分页请求form
 * <p>通过方法{@link PageForm#makePagination()}转换成Pagination对象
 *
 * @see Pagination
 * @author yoara
 */
public class PageForm extends DataAuthForm {
    @Schema(name = "页容量参数，默认20",example = "20")
    @Min(message = "页容量参数不得为空",value=1)
    private int pageSize = 20;

    @Schema(name = "当前页，默认1",example = "1")
    @Min(message = "当前页参数不得为空",value=1)
    private int currentPage = 1;

    @Schema(name = "是否查询总数",hidden = true)
    private boolean queryRecordCount = true;

    public <T> Pagination<T> makePagination(){
        return new Pagination<>(pageSize,currentPage,queryRecordCount);
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public boolean isQueryRecordCount() {
        return queryRecordCount;
    }

    public void setQueryRecordCount(boolean queryRecordCount) {
        this.queryRecordCount = queryRecordCount;
    }
}
